package pe.com.certicom.moviles.model.dao;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.orm.ibatis.support.SqlMapClientDaoSupport;
import org.springframework.stereotype.Repository;

import pe.com.certicom.moviles.model.beans.Usuario;
import pe.com.certicom.moviles.model.beans.UsuarioExample;

import com.ibatis.sqlmap.client.SqlMapClient;


@Repository
public class UsuarioDAOImpl extends SqlMapClientDaoSupport implements UsuarioDAO {

	@Autowired
	public void createSqlMapClient(SqlMapClient sqlMapClient){
	   setSqlMapClient(sqlMapClient);
	}
	
    /**
     * This method was generated by Apache iBATIS ibator.
     * This method corresponds to the database table usuario
     *
     * @ibatorgenerated Thu Mar 07 10:03:19 COT 2013
     */
    public UsuarioDAOImpl() {
        super();
    }

    /**
     * This method was generated by Apache iBATIS ibator.
     * This method corresponds to the database table usuario
     *
     * @ibatorgenerated Thu Mar 07 10:03:19 COT 2013
     */
    public int countByExample(UsuarioExample example) {
        Integer count = (Integer)  getSqlMapClientTemplate().queryForObject("usuario.ibatorgenerated_countByExample", example);
        return count;
    }

    /**
     * This method was generated by Apache iBATIS ibator.
     * This method corresponds to the database table usuario
     *
     * @ibatorgenerated Thu Mar 07 10:03:19 COT 2013
     */
    public int deleteByExample(UsuarioExample example) {
        int rows = getSqlMapClientTemplate().delete("usuario.ibatorgenerated_deleteByExample", example);
        return rows;
    }

    /**
     * This method was generated by Apache iBATIS ibator.
     * This method corresponds to the database table usuario
     *
     * @ibatorgenerated Thu Mar 07 10:03:19 COT 2013
     */
    public int deleteByPrimaryKey(Long idUsuario) {
        Usuario key = new Usuario();
        key.setIdUsuario(idUsuario);
        int rows = getSqlMapClientTemplate().delete("usuario.ibatorgenerated_deleteByPrimaryKey", key);
        return rows;
    }

    /**
     * This method was generated by Apache iBATIS ibator.
     * This method corresponds to the database table usuario
     *
     * @ibatorgenerated Thu Mar 07 10:03:19 COT 2013
     */
    public void insert(Usuario record) {
        getSqlMapClientTemplate().insert("usuario.ibatorgenerated_insert", record);
    }

    /**
     * This method was generated by Apache iBATIS ibator.
     * This method corresponds to the database table usuario
     *
     * @ibatorgenerated Thu Mar 07 10:03:19 COT 2013
     */
    public void insertSelective(Usuario record) {
        getSqlMapClientTemplate().insert("usuario.ibatorgenerated_insertSelective", record);
    }

    /**
     * This method was generated by Apache iBATIS ibator.
     * This method corresponds to the database table usuario
     *
     * @ibatorgenerated Thu Mar 07 10:03:19 COT 2013
     */
    @SuppressWarnings("unchecked")
    public List<Usuario> selectByExample(UsuarioExample example) {
        List<Usuario> list = getSqlMapClientTemplate().queryForList("usuario.ibatorgenerated_selectByExample", example);
        return list;
    }

    /**
     * This method was generated by Apache iBATIS ibator.
     * This method corresponds to the database table usuario
     *
     * @ibatorgenerated Thu Mar 07 10:03:19 COT 2013
     */
    public Usuario selectByPrimaryKey(Long idUsuario) {
        Usuario key = new Usuario();
        key.setIdUsuario(idUsuario);
        Usuario record = (Usuario) getSqlMapClientTemplate().queryForObject("usuario.ibatorgenerated_selectByPrimaryKey", key);
        return record;
    }

    /**
     * This method was generated by Apache iBATIS ibator.
     * This method corresponds to the database table usuario
     *
     * @ibatorgenerated Thu Mar 07 10:03:19 COT 2013
     */
    public int updateByExampleSelective(Usuario record, UsuarioExample example) {
        UpdateByExampleParms parms = new UpdateByExampleParms(record, example);
        int rows = getSqlMapClientTemplate().update("usuario.ibatorgenerated_updateByExampleSelective", parms);
        return rows;
    }

    /**
     * This method was generated by Apache iBATIS ibator.
     * This method corresponds to the database table usuario
     *
     * @ibatorgenerated Thu Mar 07 10:03:19 COT 2013
     */
    public int updateByExample(Usuario record, UsuarioExample example) {
        UpdateByExampleParms parms = new UpdateByExampleParms(record, example);
        int rows = getSqlMapClientTemplate().update("usuario.ibatorgenerated_updateByExample", parms);
        return rows;
    }

    /**
     * This method was generated by Apache iBATIS ibator.
     * This method corresponds to the database table usuario
     *
     * @ibatorgenerated Thu Mar 07 10:03:19 COT 2013
     */
    public int updateByPrimaryKeySelective(Usuario record) {
        int rows = getSqlMapClientTemplate().update("usuario.ibatorgenerated_updateByPrimaryKeySelective", record);
        return rows;
    }

    /**
     * This method was generated by Apache iBATIS ibator.
     * This method corresponds to the database table usuario
     *
     * @ibatorgenerated Thu Mar 07 10:03:19 COT 2013
     */
    public int updateByPrimaryKey(Usuario record) {
        int rows = getSqlMapClientTemplate().update("usuario.ibatorgenerated_updateByPrimaryKey", record);
        return rows;
    }

    /**
     * This class was generated by Apache iBATIS ibator.
     * This class corresponds to the database table usuario
     *
     * @ibatorgenerated Thu Mar 07 10:03:19 COT 2013
     */
    private static class UpdateByExampleParms extends UsuarioExample {
        private Object record;

        public UpdateByExampleParms(Object record, UsuarioExample example) {
            super(example);
            this.record = record;
        }

        public Object getRecord() {
            return record;
        }
    }

	@Override
	public long siguienteSecuencia(String nombreSecuencia) {
		// TODO Auto-generated method stub
		Map<String,Object> p = new HashMap<String,Object>();
		p.put("nombreSecuencia",nombreSecuencia);
		Long secuencia = (Long) getSqlMapClientTemplate().queryForObject("usuario.siguienteSecuencia", p);
        return secuencia.longValue();
	}
}